#引入依赖包
gulp = require('gulp')
del = require('del')
runSequence = require('run-sequence')
developServer = require('gulp-develop-server')
notify = require('gulp-notify')

gulp.task('default', (callback)->
  runSequence(['clean'], ['copyFiles'], ['serve', 'watch'], callback)
)
#清空
gulp.task('clean', (callback)->
  del('./dist/', callback)
)
#复制文件
gulp.task('copyFiles', ->
  gulp.src(['./src/**/*.js', './src/database*/*.db'])
  .pipe(gulp.dest('./dist/'))
)
#启动服务
gulp.task('serve', ->
  developServer.listen({
    path: './dist/index.js'
  })
)
#监视
gulp.task('watch', ->
  gulp.watch('./src/**/*.js', ['reload'])
)

gulp.task('reload', (callback)->
  runSequence(['copyFiles'], ['reload-node'], callback)
)

gulp.task('reload-node', ->
  developServer.restart()
  gulp.src('./dist/index.js')
  .pipe(notify('Server restarted ...'))
)